#pragma once
#include <souistd.h>
using namespace SOUI;

namespace qjsbind {
	template<>
	Value NewValue(Context& context, ISouiFactoryPtr v)
	{
		JSClassID clsId = JsClass<ISouiFactory>::class_id();
		if (clsId != 0) {
			Value obj = context.NewClassObject(clsId);
			auto _v = new JsProxy<ISouiFactory>(v,false);
			SetSafeThis(obj, _v);
			return obj;
		}
		return undefined_value;
	}

	template<typename T>
	Value NewSObject(Context& context, T& v) {
		JSClassID clsId = JsClass<T>::class_id();
		Value obj = context.NewClassObject(clsId);
		T* pv = new T(v);
		JsProxy<T>* _v = new JsProxy<T>(pv, true);
		SetSafeThis(obj, _v);
		return obj;
	}

	template<>
	Value NewValue(Context& context,  CRect v)
	{
		return NewSObject(context, v);
	}
	template<>
	Value NewValue(Context& context,  RECT v)
	{
		return NewSObject(context, v);
	}
	template<>
	Value NewValue(Context& context,  CPoint v)
	{
		return NewSObject(context, v);
	}
	template<>
	Value NewValue(Context& context,  POINT v)
	{
		return NewSObject(context, v);
	}

	template<>
	Value NewValue(Context& context, CSize v)
	{
		return NewSObject(context, v);
	}
	template<>
	Value NewValue(Context& context, SIZE v)
	{
		return NewSObject(context, v);
	}
	//--------------------------------------------------
	template<>
	WeakValue::operator SOUI::BUILTIN_RESTYPE() const {
		return (SOUI::BUILTIN_RESTYPE)ToInt32();
	}

	template<>
	WeakValue::operator SOUI::SObjectType() const {
		return (SOUI::SObjectType)ToInt32();
	}

	template<>
	WeakValue::operator SOUI::SingletonType() const {
		return (SOUI::SingletonType)ToInt32();
	}

	template<>
	WeakValue::operator BYTE() const {
		return (BYTE)ToInt32();
	}

	template<>
	WeakValue::operator char() const {
		return (char)ToInt32();
	}
	template<>
	WeakValue::operator wchar_t() const {
		return (wchar_t)ToInt32();
	}

	template<>
	WeakValue::operator DWORD() const {
		return ToUint32();
	}
/*
	template<>
	WeakValue::operator HMODULE() const {
		return (HMODULE)ToULong();
	}

	template<>
	WeakValue::operator HMENU() const {
		return (HMENU)ToULong();
	}

	template<>
	WeakValue::operator LPVOID()const {
		return (LPVOID)ToULong();
	}
	
	template<>
	WeakValue::operator const wchar_t *()const {
		return (LPCWSTR)ToULong();
	}
	*/

}